% This code produces Table 5: Response to Monetary Policy Shock
% for 350 and 56 sectors

    %clc
    %clear all
    clearvars -except wd
    Table5 = zeros(9,3);

    cd(fullfile(wd, 'Table5')); 

    % Table 3: 350 sectors, new case 1
    ii = 1;

    output_mu_output_341 = dlmread(['Gensys_mu_output_disaggregation_empirical_case_6params1_341.csv'],'\t',1,0);

            % output
            % impact
            Table5(1,ii) = output_mu_output_341(1,2);
            % cumulative
            Table5(2,ii) = output_mu_output_341(1,5);
            % persistence
            Table5(3,ii) = output_mu_output_341(1,37);

            % inflation
            % impact
            Table5(4,ii) = output_mu_output_341(1,3);
            % cumulative
            Table5(5,ii) = output_mu_output_341(1,6);
            % persistence
            Table5(6,ii) = output_mu_output_341(1,38);

            % real marginal costs
            % impact
            Table5(7,ii) = output_mu_output_341(1,4);
            % cumulative
            Table5(8,ii) = sum((output_mu_output_341(1,7:36))./341);
            % persistence
            Table5(9,ii) = output_mu_output_341(1,39);

            output_mu_output_56 = dlmread(['Gensys_mu_output_disaggregation_empirical_case_6params1_56.csv'],'\t',1,0);

            ii = ii + 1;
            % impact
            Table5(1,ii) = output_mu_output_56(1,2);
            % cumulative
            Table5(2,ii) = output_mu_output_56(1,5);
            % persistence
            Table5(3,ii) = output_mu_output_56(1,37);

            % inflation
            % impact
            Table5(4,ii) = output_mu_output_56(1,3);
            % cumulative
            Table5(5,ii) = output_mu_output_56(1,6);
            % persistence
            Table5(6,ii) = output_mu_output_56(1,38);

            % real marginal costs
            % impact
            Table5(7,ii) = output_mu_output_56(1,4);
            % cumulative
            Table5(8,ii) = sum((output_mu_output_56(1,7:36))./56);
            % persistence
            Table5(9,ii) = output_mu_output_56(1,39);

            output_mu_output_7 = dlmread(['Gensys_mu_output_disaggregation_empirical_case_6params1_7.csv'],'\t',1,0);

            ii = ii + 1;
            % impact
            Table5(1,ii) = output_mu_output_7(1,2);
            % cumulative
            Table5(2,ii) = output_mu_output_7(1,5);
            % persistence
            Table5(3,ii) = output_mu_output_7(1,37);

            % inflation
            % impact
            Table5(4,ii) = output_mu_output_7(1,3);
            % cumulative
            Table5(5,ii) = output_mu_output_7(1,6);
            % persistence
            Table5(6,ii) = output_mu_output_7(1,38);

            % real marginal costs
            % impact
            Table5(7,ii) = output_mu_output_7(1,4);
            % cumulative
            Table5(8,ii) = sum((output_mu_output_7(1,7:36))./7);
            % persistence
            Table5(9,ii) = output_mu_output_7(1,39);

    n_cases = 3;

    for jj=1:n_cases
        header1(:,jj) = [jj];
    end

    t5 = [header1; Table5];

    cd(fullfile(wd, 'Table5')); 

    % save summary output
        filename = ['Table_5.csv'];
        dlmwrite(filename, t5, 'precision', '%.2f', 'delimiter', '\t');

    %% Save ouput as Latex
    row_labels = {'Impact        '; 'Cumulative IRF'; 'Persistence   '};

    % save summary output as tex file
    matrixTexTable(4, Table5, row_labels,'341_56_7_mu'); 


